package dataBase;




import tools.SQLTools;

import java.util.Hashtable;

/**
 * 管理dataset的类，dataset属于轻量级，datasetinfo被设计为重量级
 * 的dataset，主要有哪个与server端，
 * @author Administrator
 *2011-2-19
 * javazgw@gmail.com
 */
public class DataSetInfo  implements Cloneable {

    DataSet ds ;
    String[] columnname = new String[]{};
    String[] columndisplayname = new String[]{};
    DataSetInfo parentdatasetinfo=null;//父数据集
    java.util.LinkedList<DataSetInfo> chileDSinfo = new java.util.LinkedList<DataSetInfo>();
    String[] parentLinkString = null; //链接父数据集的关联字段
    String[] chileLinkString = null;//子数据集和父数据集关联字段
    String datasettitle;
    String tableCss;
    boolean needdownload = true; //           第一次设计是为了com.base.myproject.server.tools;getzzz（）;为true显示下载,默认true
    Hashtable<String, String> macro = new Hashtable<String,String>();//放环境变量，方便扩展给使用的地方调用，第一次设计是为了com.base.myproject.server.tools;getzzz（）


    int colstartindex =0; //0表示不完后推，否则就是推后的列数 excel 有用

    String tableid = "";
    boolean isneedpage = false;//是否需要分页
    int perpagenum = 20;//每页记录数,默认20;
    int xianshikuaishu = 5 ;//默认显示的块数,避免太长用省略号代替

    int pagenow = 1;//当前页数 从1开始
    //  String pagesql = "";  //分页用的sql,原来的sql作为计算个数用.
    String querysql= "";

    int dstotalcount = -1;//ds的总个数,如果大于-1那么已经复制无须计算个数
    String pageurl = "";//分页时候用到的请求url,这个基本只会在jsp中使用

    boolean isNeedCheckBox = false;

    public DataSetInfo()
    {

    }
    public DataSetInfo(DataSet ds)
    {
        this.ds = ds;

    }
    public DataSetInfo (String sql) throws Exception {
        this.querysql = sql;
        this.ds = SQLTools.getInstance().query(sql);

    }
    public void addMacro(String key,String value)
    {
        this.macro.put(key, value);
    }
    public void remove(String key)
    {
        this.macro.remove(key);
    }

    public Hashtable<String, String> getMacro() {
        return macro;
    }
    public Object clone() {
        Object o = null;
        try {
            o = super.clone();
        } catch (CloneNotSupportedException e) {}
        return o;
    }
    public DataSetInfo getParentDataSetInfo() {
        return parentdatasetinfo;
    }
    public void setParentDataSetInfo(DataSetInfo DataSetInfo) {
        this.parentdatasetinfo = DataSetInfo;
        this.parentdatasetinfo.addChileDS(this);
    }
    public String[] getParentLinkString() {
        return parentLinkString;
    }
    public void setParentLinkString(String[] parentLinkString) {
        this.parentLinkString = parentLinkString;
    }
    public String[] getChileLinkString() {
        return chileLinkString;
    }
    public void setChileLinkString(String[] chileLinkString) {
        this.chileLinkString = chileLinkString;
    }
    public java.util.LinkedList<DataSetInfo> getChileDSinfo() {
        return chileDSinfo;
    }
    public void addChileDS(DataSetInfo ds)
    {
        if(!this.getChileDSinfo().contains(ds))
            this.getChileDSinfo().add(ds);
    }
    public DataSet getDs() {
        return ds;
    }
    public void setDs(DataSet ds) {
        this.ds = ds;
    }
    public String getDatasettitle() {
        return datasettitle;
    }
    public void setDatasettitle(String datasettitle) {
        this.datasettitle = datasettitle;
    }
    public String getTableCss() {
        return tableCss;
    }
    public void setTableCss(String tableCss) {
        this.tableCss = tableCss;
    }
    public String[] getColumnname() {
        return columnname;
    }
    public void setColumnname(String[] columnname) {
        this.columnname = columnname;
    }
    public String[] getColumndisplayname() {
        return columndisplayname;
    }
    public void setColumndisplayname(String[] columndisplayname) {
        this.columndisplayname = columndisplayname;
    }
    public int getColstartindex() {
        return colstartindex;
    }
    /**
     * -1表示不完后推，否则就是推后的列数 excel 有用
     * @param colstartindex
     */
    public void setColstartindex(int colstartindex) {
        this.colstartindex = colstartindex;
    }
    public String getTableid() {
        return tableid;
    }
    public void setTableid(String tableid) {
        this.tableid = tableid;
    }

    public void setNeeddownload(boolean b){this.needdownload=b;}
    public boolean getNeeddownload(){return needdownload;}

    public boolean isIsneedpage() {
        return isneedpage;
    }

    public void setIsneedpage(boolean isneedpage) {
        this.isneedpage = isneedpage;
    }

    public int getPerpagenum() {
        return perpagenum;
    }

    public void setPerpagenum(int perpagenum) {
        this.perpagenum = perpagenum;
    }

    public int getXianshikuaishu() {
        return xianshikuaishu;
    }

    public void setXianshikuaishu(int xianshikuaishu) {
        this.xianshikuaishu = xianshikuaishu;
    }

    public int getPagenow() {
        return pagenow;
    }

    public void setPagenow(int pagenow) {
        this.pagenow = pagenow;
    }

//    public String getPagesql() {
//        return pagesql;
//    }
//
//    public void setPagesql(String pagesql) {
//        this.pagesql = pagesql;
//    }

    public int getDstotalcount() {
        return dstotalcount;
    }

    public void setDstotalcount(int dstotalcount) {
        this.dstotalcount = dstotalcount;
    }

    public String getQuerysql() {
        return querysql;
    }

    public void setQuerysql(String querysql) {
        this.querysql = querysql;
    }

    public String getPageurl() {
        return pageurl;
    }

    public void setPageurl(String pageurl) {
        this.pageurl = pageurl;
    }

    public boolean isNeedCheckBox() {
        return isNeedCheckBox;
    }

    public void setNeedCheckBox(boolean needCheckBox) {
        isNeedCheckBox = needCheckBox;
    }
}